package com.gomokult.servlet.user;

import com.gomokult.entity.User;
import com.gomokult.exception.IllegalOperationException;
import com.gomokult.exception.InvalidIDException;
import com.gomokult.exception.UserRegisteredException;
import com.gomokult.service.impl.UserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/servlet/UpdateUserInfoServlet")
public class UpdateUserInfoServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        String nickname = request.getParameter("nickname");
        String profile = request.getParameter("profile");
        String email = request.getParameter("email");
        int userID = Integer.parseInt(request.getParameter("userID"));
        int executorID = Integer.parseInt(request.getParameter("executorID"));
        User user = new User();
        user.setUserID(userID);
        user.setEmail(email);
        user.setNickName(nickname);
        user.setProfile(profile);
        try {
            UserServiceImpl.getSingleton().setUserInfo(executorID,user);
        } catch (InvalidIDException e) {
            out.print("#InvalidIDException");
        } catch (IllegalOperationException e) {
            out.print("#IllegalOperationException");
        } catch (UserRegisteredException e) {
            out.print("#UserRegisteredException");
        }
    }
}
